import sys
from Tkinter import *
import re

from add_test import add_test

def fetch(ent):
  name = ent.get()
  p = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*')
  # check whether it's a valid name
  if p.match(name):
    add_test(name)
  sys.exit()

def add_test_ui():
  root = Tk()
  ent = Entry(root)
  ent.insert(0, 'Test')
  ent.icursor(0)
  ent.pack(side=TOP, fill=X)
  ent.focus()
  ent.bind('<Return>', (lambda event: fetch(ent)))
  root.mainloop()

if __name__ == "__main__":
  add_test_ui()

